<?php

namespace app\adminapi\lists\room\department;


use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\room\department\Department;

/**
 * 科室管理列表
 * Class RoomDepartmentLists
 * @package app\adminapi\listsroom
 */
class DepartmentLists extends BaseAdminDataLists implements ListsSearchInterface
{


    /**
     * @notes 设置搜索条件
     * @return \string[][]
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function setSearch(): array
    {
        return [
            '=' => ['id', 'cid','status'],
            "%like%" => ['code', 'name']
        ];
    }


    /**
     * @notes 获取科室房间管理列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function lists(): array
    {
        return Department::where($this->searchWhere)
            ->field('*')
            ->with('campus')
            ->limit($this->limitOffset, $this->limitLength)
            ->order(['id' => 'desc'])
            ->select()
            ->toArray();
    }


    /**
     * @notes 获取科室房间管理数量
     * @return int
     * @author likeadmin
     * @date 2024/02/26 16:32
     */
    public function count(): int
    {
        return Department::where($this->searchWhere)->count();
    }
}
